package com.woniu.mall.task;

import com.woniu.common.entity.Result;
import com.woniu.mall.constant.OrderConstants;
import com.woniu.pay.feign.PayFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PayStatusCheckTask {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private PayFeignClient payFeignClient;

    /**
     * 定时任务查询队列中的订单支付状态
     * @return
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public Result checkPayStatus(){
        String outTradeNo = redisTemplate.boundListOps(OrderConstants.QUERY_ORDER_TRADE_NO).rightPop().toString();
        Object payStatus = payFeignClient.queryStatusByOutTradeNo(outTradeNo).getData();
        log.debug("定时任务主动查询支付状态为：{}",payStatus);
        return Result.ok(payStatus);
    }
}
